package com.jack.leetcode.string;

public class 最长公共前缀 {

    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0) {
            return "";
        }
        String s = strs[0];
        int n = s.length();
        int index = 0;
        while (true && index < n) {
            boolean isIndex = true;
            for (int i = 1; i < strs.length; i++) {
                if(index >= strs[i].length()||strs[i].charAt(index) != s.charAt(index)){
                    isIndex = false;
                    break;
                }
            }
            if (!isIndex) {
                break;
            }
            index++;
        }
        return s.substring(0, index);
    }
}
